﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Medianamik.Core
{
    /// <summary>
    /// Implémentation générique du Singleton
    /// Voir : http://mostlylucid.net/archive/2008/04/30/grrr.poor-use-of-singletons-and-a-very-cool-generic-singleton.aspx
    /// </summary>
    public class Singleton<T> where T:new()
    {
        protected Singleton() { }

        public static T Instance
        {
            get
            {
                return Nested.instance;
            }
        }
        class Nested
        {
            // Explicit static constructor to tell C# compiler
            // not to mark type as beforefieldinit
            static Nested() { }
            internal static readonly T instance = new T();
        }
    }
}
